package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.vo.request.*;
import com.zhijian.medical.entity.vo.response.*;
import com.zhijian.medical.service.*;
import com.zhijian.medical.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 荧光PCR
 *
 * @author HCG
 * @version 1.0
 * @date 2022-08-30 15:34:00
 */
@Slf4j
@Controller
@Api(tags = "荧光PCR")
public class PcrController {

    @Autowired
    private PcrService service;

    @Autowired
    private PcrHskzyqService pcrHskzyqService;

    @Autowired
    private PcrSjpzqService pcrSjpzqService;

    @Autowired
    private PcrHszbqService pcrHszbqService;

    @Autowired
    private PcrYbzbService pcrYbzbService;

    @Autowired
    private PcrKzyService pcrKzyService;

    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/pcr")
    @ApiOperation("新增")
    public boolean insert(@RequestBody PcrSaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.insert(param) != null;
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/pcr/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/pcr/{id}")
    @ApiOperation("修改")
    public boolean update(@PathVariable("id") Long id, @RequestBody PcrSaveOrUpdateVo param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.update(param);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/pcr/{id}")
    @ApiOperation("根据id查询")
    public PcrVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/pcr/page")
    @ApiOperation("分页查询")
    public Page<PcrVo> selectByCondition(@RequestBody(required = false) PcrSearchVo param) {
        if (param == null)
            param = PcrSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
     * 新增or修改样本准备区数据
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/pcr/ybzb")
    @ApiOperation("新增or修改样本准备区数据")
    public boolean saveOrUpdatePcrYbzb(@RequestBody PcrYbzbSaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return pcrYbzbService.saveOrUpdate(param);
    }

    /**
     * 查询样本准备区数据
     *
     * @param pcrId
     * @return
     */
    @Response
    @GetMapping("/pcr/ybzb/{pcrId}")
    @ApiOperation("查询样本准备区数据")
    public PcrYbzbVo selectPcrYbzbByPcrId(@PathVariable("pcrId") Long pcrId) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), pcrId);
        return pcrYbzbService.selectVoByPcrId(pcrId);
    }

    /**
     * 新增or修改核酸制备区数据
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/pcr/hszbq")
    @ApiOperation("新增or修改核酸制备区数据")
    public boolean saveOrUpdatePcrHszbq(@RequestBody PcrHszbqSaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return pcrHszbqService.saveOrUpdate(param);
    }

    /**
     * 查询核酸制备区数据
     *
     * @param pcrId
     * @return
     */
    @Response
    @GetMapping("/pcr/hszbq/{pcrId}")
    @ApiOperation("查询核酸制备区数据")
    public PcrHszbqVo selectPcrHszbqById(@PathVariable("pcrId") Long pcrId) {
        return pcrHszbqService.selectVoByPcrId(pcrId);
    }

    /**
     * 核酸制备区csv文件导入
     *
     * @param pcrId
     * @param file
     * @return
     */
    @Response
    @PostMapping("/pcr/hszbq/csv/import/{pcrId}")
    @ApiOperation("核酸制备区csv文件导入")
    public List<ExperimentProcessSampleVo> importCsv(@ApiParam(name = "pcrId", value = "实验流程id") @RequestParam(value = "pcrId") Long pcrId, MultipartFile file) {
        return service.importCsv(pcrId, file);
    }

    /**
     * 新增or修改试剂配置区数据
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/pcr/sjpzq")
    @ApiOperation("新增or修改试剂配置区数据")
    public boolean saveOrUpdatePcrSjpzq(@RequestBody PcrSjpzqSaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return pcrSjpzqService.saveOrUpdate(param);
    }

    /**
     * 查询试剂配置区数据
     *
     * @param pcrId
     * @return
     */
    @Response
    @GetMapping("/pcr/sjpzq/{pcrId}")
    @ApiOperation("查询试剂配置区数据")
    public PcrSjpzqVo selectPcrSjpzqByPcrId(@PathVariable("pcrId") Long pcrId) {
        return pcrSjpzqService.selectVoByPcrId(pcrId);
    }


    /**
     * 新增or修改核酸扩增一区数据
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/pcr/hskzyq")
    @ApiOperation("新增or修改核酸扩增一区数据")
    public boolean saveOrUpdatePcrHskzyq(@RequestBody PcrHskzyqSaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return pcrHskzyqService.saveOrUpdate(param);
    }

    /**
     * 查询核酸扩增一区数据
     *
     * @param pcrId
     * @return
     */
    @Response
    @GetMapping("/pcr/hskzyq/{pcrId}")
    @ApiOperation("查询核酸扩增一区数据")
    public PcrHskzyqVo selectPcrHskzyqByPcrId(@PathVariable("pcrId") Long pcrId) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), pcrId);
        return pcrHskzyqService.selectVoByPcrId(pcrId);
    }

    /**
     * 核酸扩增一区excel文件导入
     *
     * @param experimentProcessId
     * @param file
     * @return
     */
    @Response
    @PostMapping("/pcr/hskzyq/import/{experimentProcessId}/{deviceId}")
    @ApiOperation("核酸扩增一区excel文件导入")
    public boolean importExcel(@ApiParam(name = "experimentProcessId", value = "实验流程id")
                               @PathVariable("experimentProcessId") Long experimentProcessId,
                               @ApiParam(name = "deviceId", value = "扩增仪id")
                               @PathVariable("deviceId") Long deviceId,
                               MultipartFile file) {
        return pcrKzyService.importExcel(experimentProcessId, deviceId, file);
    }

    /**
     * 查询一个实验流程的扩增仪所有数据列表
     *
     * @param pcrId
     * @return
     */
    @Response
    @GetMapping("/pcr/hskzyq/kzy/all/data/{pcrId}")
    @ApiOperation("查询一个实验流程的扩增仪所有数据列表")
    public List<PcrOfKzyVo> selectExperimentProcessOfKzyVoByExperimentProcessId(@PathVariable("pcrId") Long pcrId) {
        return pcrKzyService.selectPcrOfKzyVoByPcrId(pcrId);
    }

    /**
     * KNB生成实验报告
     *
     * @param pcrId
     * @return
     */
    @Response
    @PostMapping("/pcr/knb/create/report/{pcrId}")
    @ApiOperation("KNB生成实验报告")
    public boolean createKnbReport(@ApiParam(name = "pcrId", value = "实验流程id")
                                   @PathVariable("pcrId") Long pcrId) {
        return service.createKnbReport(pcrId);
    }

    /**
     * 新冠病毒生成实验报告
     *
     * @param pcrId
     * @return
     */
    @Response
    @PostMapping("/pcr/cov/create/report/{pcrId}")
    @ApiOperation("新冠病毒生成实验报告")
    public boolean createCovReport(@ApiParam(name = "pcrId", value = "实验流程id")
                                   @PathVariable("pcrId") Long pcrId) {
        return service.createCovReport(pcrId);
    }

}